package com.ruoyi.web.controller.net;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.net.domain.*;
import com.ruoyi.net.netconf.Device;
import com.ruoyi.net.netconf.util.DeviceManager;
import com.ruoyi.net.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;

/**
 * 业务-srtp配置Controller
 * 
 * @author net
 * @date 2024-12-05
 */
@Api(tags = "业务-srtp配置")
@RestController
@RequestMapping("/busi/srtp")
public class BusiSrtpController extends BaseController
{
    @Autowired
    private IBusiSrtpService busiSrtpService;
    @Autowired
    private IBusiSrtpElementService busiSrtpElementService;
    @Autowired
    private DeviceManager deviceManager;

    @Autowired
    private INetElementService netElementService;

    @Autowired
    private IElementBusiSrtpAlarmoamService elementBusiSrtpAlarmoamService;

    @Autowired
    private IBusiElementStatusService busiElementStatusService;
    /**
     * 查询业务-srtp配置列表
     */
    @ApiOperation(value = "查询业务-srtp配置列表", httpMethod = "GET")
    @PreAuthorize("@ss.hasPermi('net:srtp:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusiSrtp busiSrtp)
    {
        startPage();
        List<BusiSrtpListVo> list = busiSrtpService.selectBusiSrtpList(busiSrtp);
        return getDataTable(list);
    }
    /**
     * 查询网元-业务-eline列表
     */
    @ApiOperation(value = "查询网元-业务-SR配置-srtp", httpMethod = "GET")
    @GetMapping("/ele/list")
    public TableDataInfo eleList(BusiSrtpListVo busiSrtp)
    {
        startPage();
        List<BusiSrtpListVo> list = busiSrtpService.selectBusiSrtpEleList(busiSrtp);
        return getDataTable(list);
    }

    /**
     * 导出业务-srtp配置列表
     */
    @ApiOperation(value = "导出业务-srtp配置列表", httpMethod = "POST")
    @PreAuthorize("@ss.hasPermi('net:srtp:export')")
    @Log(title = "业务-srtp配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusiSrtp busiSrtp)
    {
        List<BusiSrtpListVo> list = busiSrtpService.selectBusiSrtpList(busiSrtp);
        ExcelUtil<BusiSrtpListVo> util = new ExcelUtil<BusiSrtpListVo>(BusiSrtpListVo.class);
        util.exportExcel(response, list, "业务-srtp配置数据");
    }

    /**
     * 获取业务-srtp配置详细信息
     */
    @ApiOperation(value = "获取业务-srtp配置详细信息", httpMethod = "GET")
    @PreAuthorize("@ss.hasPermi('net:srtp:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(busiSrtpService.selectBusiSrtpById(id));
    }

    /**
     * 新增业务-srtp配置
     */
    @ApiOperation(value = "新增业务-srtp配置", httpMethod = "POST")
    @PreAuthorize("@ss.hasPermi('net:srtp:add')")
    @Log(title = "业务-srtp配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusiSrtpVo busiSrtpVo)
    {
        return toAjax(busiSrtpService.insertBusiSrtp(busiSrtpVo));
    }

    /**
     * 修改业务-srtp配置
     */
    @ApiOperation(value = "修改业务-srtp配置", httpMethod = "PUT")
    @PreAuthorize("@ss.hasPermi('net:srtp:edit')")
    @Log(title = "业务-srtp配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusiSrtp busiSrtp)
    {
        return toAjax(busiSrtpService.updateBusiSrtp(busiSrtp));
    }

    /**
     * 删除业务-srtp配置
     */
    @ApiOperation(value = "删除业务-srtp配置", httpMethod = "DELETE")
    @PreAuthorize("@ss.hasPermi('net:srtp:remove')")
    @Log(title = "业务-srtp配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(busiSrtpService.deleteBusiSrtpByIds(ids));
    }
    @ApiOperation(value = "点击'完成'按钮更新业务-srtp配置状态", httpMethod = "PUT")
    @PreAuthorize("@ss.hasPermi('net:mplstp:edit')")
    @Log(title = "业务-srtp配置", businessType = BusinessType.UPDATE)
    @PutMapping("/complete")
    public AjaxResult complete(@RequestBody BusiSrtp busiSrtp)
    {
        return toAjax(busiSrtpService.updateBusiSrtp(busiSrtp));
    }
    @ApiOperation(value = "激活设备", httpMethod = "GET")
    @GetMapping(value = "/activate2/{id}")
    @Log(title = "激活设备", businessType = BusinessType.UPDATE)
    public AjaxResult activateDevice2(@PathVariable("srtpId") String srtpId,@PathVariable("elementId") String elementId) {
        BusiSrtp busiMplstp = busiSrtpService.selectBusiSrtpById(srtpId);
        return null;
    }
    /**
     * 批量激活设备
     *
     * @param
     */
    @ApiOperation(value = "业务管理界面批量激活设备", httpMethod = "GET")
    @GetMapping(value = "/activateAll/{srtpId}")
    @Log(title = "批量激活设备", businessType = BusinessType.UPDATE)
    public AjaxResult activateDeviceAll(@PathVariable("srtpId") String srtpId) {
        BusiSrtpElement busiSrtpElement = new BusiSrtpElement();
        busiSrtpElement.setSrtpId(srtpId);
        List<BusiSrtpElementVo> busiSrtpElementVos = busiSrtpElementService.selectBusiSrtpElementList(busiSrtpElement);
        return toAjax(batchActivate(busiSrtpElementVos));
    }
    /**
     * 批量激活
     * @param busiSrtpElementVos
     * @return
     */
    private int batchActivate(List<BusiSrtpElementVo> busiSrtpElementVos) {
        int result = 0;
        for (BusiSrtpElementVo busiSrtpElementVo : busiSrtpElementVos) {
            String elementId = busiSrtpElementVo.getElementId();
            busiSrtpElementVo.setStatus("1");
            if (sendXml2(busiSrtpElementVo, elementId)) {
                //同步业务设备网元状态
                BusiElementStatus busiElementStatus = new BusiElementStatus();
                busiElementStatus.setElementId(elementId);
                busiElementStatus.setBusiId(busiSrtpElementVo.getSrtpId());
                busiElementStatus.setStatus("1");
                busiElementStatus.setUpdateBy(SecurityUtils.getUsername());
                busiElementStatus.setUpdateTime(DateUtils.getNowDate());
                busiElementStatusService.updateBusiElementStatusByParams(busiElementStatus);
                //更新单站业务表状态
                BusiSrtpElement busiSrtpElement = new BusiSrtpElement();
                busiSrtpElement.setSrtpId(busiSrtpElementVo.getSrtpId());
                busiSrtpElement.setElementId(elementId);
                busiSrtpElement.setStatus("1");
                busiSrtpElementService.updateBusiSrtpElementByParam(busiSrtpElement);
                //更新业务表状态  部分激活2/激活1
                BusiSrtp busiSrtp = new BusiSrtp();
                BusiElementStatus busiElementStatus1 = new BusiElementStatus();
                busiElementStatus1.setBusiId(busiSrtpElementVo.getSrtpId());
                List<BusiElementStatus> statusList = busiElementStatusService.selectBusiElementStatusList(busiElementStatus1);
                Optional<BusiElementStatus> max = statusList.stream().max(Comparator.comparing(BusiElementStatus::getStatus));
                Optional<BusiElementStatus> min = statusList.stream().min(Comparator.comparing(BusiElementStatus::getStatus));
                if (max.get().getStatus().equals(min.get().getStatus())){
                    if ("0".equals(max.get().getStatus())){
                        busiSrtp.setStatus("0");
                    }else {
                        busiSrtp.setStatus("1");
                    }
                }else {
                    busiSrtp.setStatus("2");
                }
                busiSrtp.setId(busiSrtpElementVo.getSrtpId());
                result = busiSrtpService.updateBusiSrtp(busiSrtp);

            } else {
                logger.info("mplsp-业务管理批量激活-单站激活失败");
            }
        }
        return result;
    }

    /**
     * 批量去激活设备
     *
     * @param
     */
    @ApiOperation(value = "业务管理界面批量去激活设备", httpMethod = "GET")
    @GetMapping(value = "/inActivateAll/{srtpId}")
    @Log(title = "批量去激活设备", businessType = BusinessType.UPDATE)
    public AjaxResult inActivateDeviceAll(@PathVariable("srtpId") String srtpId) {
        BusiSrtpElement busiSrtpElement = new BusiSrtpElement();
        busiSrtpElement.setSrtpId(srtpId);
        List<BusiSrtpElementVo> busiSrtpElementVos = busiSrtpElementService.selectBusiSrtpElementList(busiSrtpElement);
        return toAjax(batchInActivate(busiSrtpElementVos));
    }
    /**
     * 批量去激活
     * @param busiSrtpElementVos
     * @return
     */
    private int batchInActivate(List<BusiSrtpElementVo> busiSrtpElementVos) {
        int result = 0;
        for (BusiSrtpElementVo busiSrtpElementVo : busiSrtpElementVos) {
            String elementId = busiSrtpElementVo.getElementId();
            busiSrtpElementVo.setStatus("0");
            if (sendXml2(busiSrtpElementVo, elementId)) {
                //同步业务设备网元状态
                BusiElementStatus busiElementStatus = new BusiElementStatus();
                busiElementStatus.setElementId(elementId);
                busiElementStatus.setBusiId(busiSrtpElementVo.getSrtpId());
                busiElementStatus.setStatus("0");
                busiElementStatus.setUpdateBy(SecurityUtils.getUsername());
                busiElementStatus.setUpdateTime(DateUtils.getNowDate());
                busiElementStatusService.updateBusiElementStatusByParams(busiElementStatus);
                //更新单站业务表状态
                BusiSrtpElement busiSrtpElement = new BusiSrtpElement();
                busiSrtpElement.setSrtpId(busiSrtpElementVo.getSrtpId());
                busiSrtpElement.setElementId(elementId);
                busiSrtpElement.setStatus("0");
                busiSrtpElementService.updateBusiSrtpElementByParam(busiSrtpElement);
                //更新业务表状态  部分激活2/激活1
                BusiSrtp busiSrtp = new BusiSrtp();
                BusiElementStatus busiElementStatus1 = new BusiElementStatus();
                busiElementStatus1.setBusiId(busiSrtpElementVo.getSrtpId());
                List<BusiElementStatus> statusList = busiElementStatusService.selectBusiElementStatusList(busiElementStatus1);
                Optional<BusiElementStatus> max = statusList.stream().max(Comparator.comparing(BusiElementStatus::getStatus));
                Optional<BusiElementStatus> min = statusList.stream().min(Comparator.comparing(BusiElementStatus::getStatus));
                if (max.get().getStatus().equals(min.get().getStatus())){
                    if ("0".equals(max.get().getStatus())){
                        busiSrtp.setStatus("0");
                    }else {
                        busiSrtp.setStatus("1");
                    }
                }else {
                    busiSrtp.setStatus("2");
                }
                busiSrtp.setId(busiSrtpElementVo.getSrtpId());
                result = busiSrtpService.updateBusiSrtp(busiSrtp);

            } else {
                logger.info("mplsp-业务管理批量去激活-单站激活失败");
            }
        }
        return result;
    }
    /**
     * 激活设备
     *
     * @param srtpSingleId
     * @param elementId
     */
    @ApiOperation(value = "激活设备", httpMethod = "GET")
    @GetMapping(value = "/activate/{srtpSingleId}/{elementId}")
    @Log(title = "激活设备", businessType = BusinessType.UPDATE)
    public AjaxResult activateDevice(@PathVariable("srtpSingleId") String srtpSingleId,@PathVariable("elementId") String elementId) {
        BusiSrtpElementVo busiSrtpElementVo = busiSrtpElementService.selectBusiSrtpElementVoById(srtpSingleId);
        //确定操作类型
        busiSrtpElementVo.setStatus("1");
        if (sendXml2(busiSrtpElementVo, elementId)) {
            //同步业务设备网元状态
            BusiElementStatus busiElementStatus = new BusiElementStatus();
            busiElementStatus.setElementId(elementId);
            busiElementStatus.setBusiId(busiSrtpElementVo.getSrtpId());
            busiElementStatus.setStatus("1");
            busiElementStatus.setUpdateBy(SecurityUtils.getUsername());
            busiElementStatus.setUpdateTime(DateUtils.getNowDate());
            busiElementStatusService.updateBusiElementStatusByParams(busiElementStatus);
            //更新单站业务表状态
            BusiSrtpElement busiSrtpElement = new BusiSrtpElement();
            busiSrtpElement.setSrtpId(busiSrtpElementVo.getSrtpId());
            busiSrtpElement.setElementId(elementId);
            busiSrtpElement.setStatus("1");
            busiSrtpElementService.updateBusiSrtpElementByParam(busiSrtpElement);
            //更新业务表状态  部分激活2/激活1
            BusiSrtp busiSrtp = new BusiSrtp();
            BusiElementStatus busiElementStatus1 = new BusiElementStatus();
            busiElementStatus1.setBusiId(busiSrtpElementVo.getSrtpId());
            List<BusiElementStatus> statusList = busiElementStatusService.selectBusiElementStatusList(busiElementStatus1);
            Optional<BusiElementStatus> max = statusList.stream().max(Comparator.comparing(BusiElementStatus::getStatus));
            Optional<BusiElementStatus> min = statusList.stream().min(Comparator.comparing(BusiElementStatus::getStatus));
            if (max.get().getStatus().equals(min.get().getStatus())){
                if ("0".equals(max.get().getStatus())){
                    busiSrtp.setStatus("0");
                }else {
                    busiSrtp.setStatus("1");
                }
            }else {
                busiSrtp.setStatus("2");
            }
            busiSrtp.setId(busiSrtpElementVo.getSrtpId());
            return toAjax(busiSrtpService.updateBusiSrtp(busiSrtp));
        }else{
            return AjaxResult.error("激活失败");
        }


       /* busiSrtpXmlVo.setTunnelId(busiMplstp.getTunnelId());
        ElementBusiSrtpAlarmoam oam = new ElementBusiSrtpAlarmoam();
        oam.setSrtpId(id);
        //网元id
        oam.setElementId(elementId);
        //获取oam工作属性
        oam.setRouteType("1");
        List<ElementBusiSrtpAlarmoamVo> workOamList = elementBusiSrtpAlarmoamService.selectElementBusiSrtpAlarmoamList(oam);
        if (workOamList.size()>0){
            busiSrtpXmlVo.setWorkMegName(workOamList.get(0).getMegName());
            busiSrtpXmlVo.setWorkLevel("7");
            busiSrtpXmlVo.setWorkIcc("123456");
            busiSrtpXmlVo.setWorkUmc("789ABC");
            busiSrtpXmlVo.setWorkMeName(workOamList.get(0).getMeName());
            busiSrtpXmlVo.setWorkMepId(workOamList.get(0).getMeName());//?
            busiSrtpXmlVo.setWorkRemoteMepId(workOamList.get(0).getMeName());
            busiSrtpXmlVo.setWorkCcmInterval(workOamList.get(0).getCv().replace(".","_"));
            busiSrtpXmlVo.setWorkOamExp(workOamList.get(0).getLspTtl().split("/")[1]);
            busiSrtpXmlVo.setWorkOamTtl(workOamList.get(0).getLspTtl().split("/")[0]);
        }
        //获取oam保护属性

        oam.setRouteType("2");
        List<ElementBusiSrtpAlarmoamVo> proOamList = elementBusiSrtpAlarmoamService.selectElementBusiSrtpAlarmoamList(oam);
        if (proOamList.size()>0){
            busiSrtpXmlVo.setProMegName(proOamList.get(0).getMegName());
            busiSrtpXmlVo.setProLevel("7");
            busiSrtpXmlVo.setProIcc("123456");
            busiSrtpXmlVo.setProUmc("789ABC");
            busiSrtpXmlVo.setProMeName(proOamList.get(0).getMeName());
            busiSrtpXmlVo.setProMepId(proOamList.get(0).getMeName());//?
            busiSrtpXmlVo.setProRemoteMepId(proOamList.get(0).getMeName());
            busiSrtpXmlVo.setProCcmInterval(proOamList.get(0).getCv().replace(".","_"));
            busiSrtpXmlVo.setProOamExp(proOamList.get(0).getLspTtl().split("/")[1]);
            busiSrtpXmlVo.setProOamTtl(proOamList.get(0).getLspTtl().split("/")[0]);

        }
        //获取邻接标签
        BusiNeighbLabelVo busiNeighbLabel = new BusiNeighbLabelVo();
        busiNeighbLabel.setElementId(elementId);
        BusiSrtpRouteTable busiSrtpRouteTable =new BusiSrtpRouteTable();
        busiSrtpRouteTable.setSrtpId(id);
        busiSrtpRouteTable.setRouteType("1");
        busiSrtpRouteTable.setRouteDirection("1");
        busiSrtpRouteTable.setServiceFlag("N");
        busiSrtpRouteTable.setElementId(elementId);
        List<BusiSrtpRouteListVoTable> busiSrtpRouteListVoTables = busiSrtpRouteTableService.selectBusiSrtpRouteTableList(busiSrtpRouteTable);
        if (busiSrtpRouteListVoTables.size()>0){
            busiNeighbLabel.setStartPortId(busiSrtpRouteListVoTables.get(0).getPortId());
            ElementPortMode elementPortMode = portModeService.selectElementPortModeById(busiSrtpRouteListVoTables.get(0).getPortId());
            busiSrtpXmlVo.setPortName(elementPortMode.getPortName());

            ElementPortEth elementPortEth = new ElementPortEth();
            elementPortEth.setElementId(elementId);
            elementPortEth.setPortName(busiSrtpXmlVo.getPortName());
            List<ElementPortEth> elementPortEths = elementPortEthService.selectElementPortEthList(elementPortEth);
            if (elementPortEths.size()>0){
                busiSrtpXmlVo.setMask(elementPortEths.get(0).getMask());
                busiSrtpXmlVo.setIp(elementPortEths.get(0).getIp());
                busiSrtpXmlVo.setMaxFrameLen(elementPortEths.get(0).getMaxFrameLen());
            }

        }
//        busiNeighbLabel.setStartPortId();
        List<BusiNeighbLabelListVo> busiNeighbLabelListVos = busiNeighbLabelService.selectBusiNeighbLabelEleList(busiNeighbLabel);
        //设置源 相关信息
        if (busiNeighbLabelListVos.size()>0){
            busiSrtpXmlVo.setWorkNextHop(busiNeighbLabelListVos.get(0).getStartOppositeIp());
            busiSrtpXmlVo.setWorkOutIfName(busiNeighbLabelListVos.get(0).getStartPortName());
            busiSrtpXmlVo.setWorkSidValue(busiNeighbLabelListVos.get(0).getStartNeighbLabel());
        }
        //设置宿 相关信息
      *//*  if (busiNeighbLabelListVos.size()>0){
            busiSrtpXmlVo.setProNextHop(busiNeighbLabelListVos.get(0).getStartOppositeIp());
            busiSrtpXmlVo.setProOutIfName(busiNeighbLabelListVos.get(0).getStartPortName());
            busiSrtpXmlVo.setProSidValue(busiNeighbLabelListVos.get(0).getStartNeighbLabel());
        }*//*
        //获取保护属性信息
        ElementBusiSrtpProtect elementBusiSrtpProtect = new ElementBusiSrtpProtect();
        elementBusiSrtpProtect.setSrtpId(id);
        //一个业务只会生成一条保护属性数据
        List<ElementBusiSrtpProtect> elementBusiSrtpProtects = elementBusiSrtpProtectService.selectElementBusiSrtpProtectList(elementBusiSrtpProtect);
        if (elementBusiSrtpProtects.size()>0){
            busiSrtpXmlVo.setHoldOffTime(elementBusiSrtpProtects.get(0).getDelayTime());
            busiSrtpXmlVo.setWtr(elementBusiSrtpProtects.get(0).getWaitTime());
        }
        busiMplstp.setStatus("1");
        busiSrtpXmlVo.setElementId(elementId);
        busiSrtpXmlVo.setStatus("1");
        if (sendXml(busiSrtpXmlVo)){
            return toAjax(busiSrtpService.updateBusiSrtp(busiMplstp));
        }else {
            return AjaxResult.error("激活设备失败");
        }*/
    }
    /**
     * 去激活设备
     *
     * @param srtpSingleId
     */
    @ApiOperation(value = "去激活设备", httpMethod = "GET")
    @Log(title = "去激活设备", businessType = BusinessType.UPDATE)
    @GetMapping(value = "/unactivate/{srtpSingleId}/{elementId}")
    public AjaxResult unactivateDevice(@PathVariable("srtpSingleId") String srtpSingleId,@PathVariable("elementId") String elementId) {
        BusiSrtpElementVo busiSrtpElementVo = busiSrtpElementService.selectBusiSrtpElementVoById(srtpSingleId);
        //确定操作类型-去激活
        busiSrtpElementVo.setStatus("0");
        if (sendXml2(busiSrtpElementVo, elementId)) {
            //同步业务设备网元状态
            BusiElementStatus busiElementStatus = new BusiElementStatus();
            busiElementStatus.setElementId(elementId);
            busiElementStatus.setBusiId(busiSrtpElementVo.getSrtpId());
            busiElementStatus.setStatus("0");
            busiElementStatus.setUpdateBy(SecurityUtils.getUsername());
            busiElementStatus.setUpdateTime(DateUtils.getNowDate());
            busiElementStatusService.updateBusiElementStatusByParams(busiElementStatus);
            //更新单站业务表状态
            BusiSrtpElement busiSrtpElement = new BusiSrtpElement();
            busiSrtpElement.setSrtpId(busiSrtpElementVo.getSrtpId());
            busiSrtpElement.setElementId(elementId);
            busiSrtpElement.setStatus("0");
            busiSrtpElementService.updateBusiSrtpElementByParam(busiSrtpElement);
            //更新业务表状态  部分激活2/激活1
            BusiSrtp busiSrtp = new BusiSrtp();
            BusiElementStatus busiElementStatus1 = new BusiElementStatus();
            busiElementStatus1.setBusiId(busiSrtpElementVo.getSrtpId());
            List<BusiElementStatus> statusList = busiElementStatusService.selectBusiElementStatusList(busiElementStatus1);
            Optional<BusiElementStatus> max = statusList.stream().max(Comparator.comparing(BusiElementStatus::getStatus));
            Optional<BusiElementStatus> min = statusList.stream().min(Comparator.comparing(BusiElementStatus::getStatus));
            if (max.get().getStatus().equals(min.get().getStatus())){
                if ("0".equals(max.get().getStatus())){
                    busiSrtp.setStatus("0");
                }else {
                    busiSrtp.setStatus("1");
                }
            }else {
                busiSrtp.setStatus("2");
            }
            busiSrtp.setId(busiSrtpElementVo.getSrtpId());
            return toAjax(busiSrtpService.updateBusiSrtp(busiSrtp));
        }else{
            return AjaxResult.error("去激活设备失败");
        }
    }

    /**
     * 发送xml到设备
     *
     * @param busiSrtpXmlVo
     */
    private boolean sendXml(BusiSrtpXmlVo busiSrtpXmlVo) {
        // TODO: 2024/11/22 待与设备联调
        boolean isSend = false;
        NetElement netElement = netElementService.getCacheObject(busiSrtpXmlVo.getElementId());
        Device device = deviceManager.getDevice(netElement.getIp());
        if (device.isConnected()) {
            //1、先下以太接口（小颗粒往后），mpls
            String xml = "";
            busiSrtpXmlVo.setWorkNextHop("10.12.1.1");
            busiSrtpXmlVo.setWorkOutIfName("eth-1gi0/1/0/5");
            busiSrtpXmlVo.setWorkSidValue("17");
            String xml1 = "";
            if ("1".equals(busiSrtpXmlVo.getStatus())) {
                xml1 +=
                        "<if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" +
                                "<interfaces>";
                xml1 += "          <interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">";
                xml1 += "            <name>" + busiSrtpXmlVo.getPortName() + "</name>" +//以太主接口
                        "            <type>ETH-PHY</type>" +
                        "            <enabled>enable</enabled>" +
                        "            <eth-option xmlns=\"http://fiberhome.com/fhnw/yang/interface/ethinterface/fos-ethif-common\">" +
                        "              <loop-block>disable</loop-block>" +
                        "            </eth-option>" +
                        "            <ethphy-interface xmlns=\"http://fiberhome.com/fhnw/yang/interface/ethinterface/fos-ethif-phy\">" +
                        "              <up-holdtime>200</up-holdtime>" +
                        "              <down-holdtime>0</down-holdtime>" +
                        "              <tp-mode-enable>disable</tp-mode-enable>" +
//                        "              <port-mode>lan</port-mode>" +//删除
                        "              <port-laser-startup-delay-time>0</port-laser-startup-delay-time>" +
                        "              <energy-saving-mode>disable</energy-saving-mode>" +
                        "  <negotiation-enable>disable</negotiation-enable>" +//?????

                        "            </ethphy-interface>" +
                        "            <transport-layer xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-l2l3common\">layer-3-route</transport-layer>" +
                        "            <ip xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-l2l3common\">" +
                        "              <ipv4-mtu>" + busiSrtpXmlVo.getMaxFrameLen() + "</ipv4-mtu>" +
                        "              <ipv4-address-list>" +
                        "                <ipv4-address>" + busiSrtpXmlVo.getIp() + "/" + busiSrtpXmlVo.getMask() + "</ipv4-address>" +//配置L3模式的接口IP  需要从以太接口获取
                        "                <secondry-use>mast</secondry-use>" +
                        "              </ipv4-address-list>" +
                        "            </ip>" +
                        "            <qos-policy-cfgs xmlns=\"http://fiberhome.com/fhnw/yang/qos/fos-qos\"/>" +
                        "          </interface>" +
                        "        </interfaces>" +
                        "      </if>";

                logger.info("srtp-以太报文数据xml1-1：" + xml1.toString());
                //tp-oam 工作路径  2.8连设备测试通过
         /*   String xml = " <tpoam xmlns=\"http://fiberhome.com/fhnw/yang/oam/fos-tpoam\">" +
                    "        <meg-cfg>" +
                    "          <meg-list>" +
                    "            <meg-name>meg5b7d0038</meg-name>" +//关键字，string 1-31
                    "            <level>7</level>" +//MEG级别0-7
                    "            <icc>123456</icc>" +//sting,1-6
                    "            <umc>789ABC</umc>" +//string,1-6
                    "            <me-list>" +
                    "              <me-name>1</me-name>" +//关键字
                    "              <mep-id>1</mep-id>" +//源MEP ID，1-8191    ？？meg信息？
                    "              <remote-mep-id>2</remote-mep-id>" +//目的MEP ID，1-8191
                    "              <mp-type>mep</mp-type>" +//节点类型，源宿取值mep,
                    "              <ccm-send-enable>enable</ccm-send-enable>" +//CCM发送使能
                    "              <ccm-interval>3_33ms</ccm-interval>" +//CCM 发送间隔
                    "              <aps-send-enable>disable</aps-send-enable>" +//APS 使能
                    "              <fdi-send-enable>disable</fdi-send-enable>" +//FDI使能
                    "              <csf-send-enable>disable</csf-send-enable>" +//CSF使能
                    "              <oam-exp>7</oam-exp>" +//OAM的EXP配置，uint8，0-7
                    "              <oam-ttl>255</oam-ttl>" +//OAM 的TTL uint8,1-255
                    "              <dual-lm-enable>disable</dual-lm-enable>" +//双向LM使能
                    "            </me-list>" +
                    "          </meg-list>" +
                    "        </meg-cfg>" +
                    "      </tpoam>";*/
                //工作路径-oam srtp默认带保护
                String xml3 = "<tpoam xmlns=\"http://fiberhome.com/fhnw/yang/oam/fos-tpoam\">" +
                        "        <meg-cfg>" +
                        "          <meg-list>" +
                        "            <meg-name>" + busiSrtpXmlVo.getWorkMegName() + "</meg-name>" +//关键字，string 1-31  meg+十位数字转16进制
                        "            <level>7</level>" +//MEG级别0-7
                        "            <icc>123456</icc>" +//sting,1-6
                        "            <umc>789ABC</umc>" +//string,1-6
                        "            <me-list>" +
                        "              <me-name>" + busiSrtpXmlVo.getWorkMeName() + "</me-name>" +//关键字 me
                        "              <mep-id>" + busiSrtpXmlVo.getWorkMepId() + "</mep-id>" +//源MEP ID，1-8191   取倒数二 三  工作下的两条数据相反    1/2/7  2/1/7    保护下的两条数据相反
                        "              <remote-mep-id>" + busiSrtpXmlVo.getWorkRemoteMepId() + "</remote-mep-id>" +//目的MEP ID，1-8191
                        "              <mp-type>mep</mp-type>" +//节点类型，源宿取值mep,
                        "              <ccm-send-enable>enable</ccm-send-enable>" +//CCM发送使能
                        "              <ccm-interval>" + busiSrtpXmlVo.getWorkCcmInterval() + "</ccm-interval>" +//CCM 发送间隔   3.33 .替换为下划线
                        "              <aps-send-enable>disable</aps-send-enable>" +//APS 使能
                        "              <fdi-send-enable>disable</fdi-send-enable>" +//FDI使能
                        "              <csf-send-enable>disable</csf-send-enable>" +//CSF使能   写死
                        "              <oam-exp>" + busiSrtpXmlVo.getWorkOamExp() + "</oam-exp>" +//OAM的EXP配置，uint8，0-7    LSP TTL/EXP
                        "              <oam-ttl>" + busiSrtpXmlVo.getWorkOamTtl() + "</oam-ttl>" +//OAM 的TTL uint8,1-255     LSP TTL/EXP
                        "              <dual-lm-enable>disable</dual-lm-enable>" +//双向LM使能  写死
                        "            </me-list>" +
                        "          </meg-list>" +
                        "        </meg-cfg>" +
                        "      </tpoam>";
                //保护路径-oam

                xml3 += " <tpoam xmlns=\"http://fiberhome.com/fhnw/yang/oam/fos-tpoam\">" +
                        "        <meg-cfg>" +
                        "          <meg-list>" +
                        "            <meg-name>" + busiSrtpXmlVo.getProMegName() + "</meg-name>" +//关键字，string 1-31  meg+十位数字转16进制
                        "            <level>7</level>" +//MEG级别0-7
                        "            <icc>123456</icc>" +//sting,1-6
                        "            <umc>789ABC</umc>" +//string,1-6
                        "            <me-list>" +
                        "              <me-name>" + busiSrtpXmlVo.getProMeName() + "</me-name>" +//关键字 me
                        "              <mep-id>" + busiSrtpXmlVo.getProMepId() + "</mep-id>" +//源MEP ID，1-8191   取倒数二 三  工作下的两条数据相反    1/2/7  2/1/7    保护下的两条数据相反
                        "              <remote-mep-id>" + busiSrtpXmlVo.getProRemoteMepId() + "</remote-mep-id>" +//目的MEP ID，1-8191
                        "              <mp-type>mep</mp-type>" +//节点类型，源宿取值mep,
                        "              <ccm-send-enable>enable</ccm-send-enable>" +//CCM发送使能
                        "              <ccm-interval>" + busiSrtpXmlVo.getProCcmInterval() + "</ccm-interval>" +//CCM 发送间隔   3.33 .替换为下划线
                        "              <aps-send-enable>disable</aps-send-enable>" +//APS 使能
                        "              <fdi-send-enable>disable</fdi-send-enable>" +//FDI使能
                        "              <csf-send-enable>disable</csf-send-enable>" +//CSF使能   写死
                        "              <oam-exp>" + busiSrtpXmlVo.getProOamExp() + "</oam-exp>" +//OAM的EXP配置，uint8，0-7    LSP TTL/EXP
                        "              <oam-ttl>" + busiSrtpXmlVo.getProOamTtl() + "</oam-ttl>" +//OAM 的TTL uint8,1-255     LSP TTL/EXP
                        "              <dual-lm-enable>disable</dual-lm-enable>" +//双向LM使能  写死
                        "            </me-list>" +
                        "          </meg-list>" +
                        "        </meg-cfg>" +
                        "      </tpoam>";
                //srtp-邻接标签
                xml3 += "  <mpls xmlns=\"http://fiberhome.com/fhnw/yang/mplsprotocol/fos-mpls\">" +
                        "        <static-sr>" +
                        "          <static-sr-adjacency nc:operation=\"create\">" +
                        "\t\t\t<nexthop>" + busiSrtpXmlVo.getWorkNextHop() + "</nexthop>" +//下一跳，对端端口IP
                        "\t\t\t<out-ifname>" + busiSrtpXmlVo.getWorkOutIfName() + "</out-ifname>" +//出接口     取sr邻接标签表信息          与实际不符 	实际是eth-1gi0/1/0/2  因为是小颗粒
                        "\t\t\t<sid-value>" + busiSrtpXmlVo.getWorkSidValue() + "</sid-value>" +//邻接标签
                        "          </static-sr-adjacency>" +
                        "        </static-sr>" +
                        "        <mpls-te/>" +
                        "      </mpls>";
                xml3 += "<mpls xmlns=\"http://fiberhome.com/fhnw/yang/mplsprotocol/fos-mpls\">" +
                        "        <mpls-te>" +
                        "          <tunnel-te nc:operation=\"create\">" +
                        "            <id>" + busiSrtpXmlVo.getTunnelId() + "</id>" +//   srtp主表字段 tunnelId
                        "            <revertive-mode>revertive</revertive-mode>" +
                        "            <wtr>" + busiSrtpXmlVo.getWtr() + "</wtr>" +//等待恢复时间  保护属性
                        "            <holdoff-time>" + busiSrtpXmlVo.getHoldOffTime() + "</holdoff-time>" +//保护属性  延迟时间
                        "            <vpoams xmlns=\"http://fiberhome.com/fhnw/yang/oam/fos-tpoam\">" +
                        "              <vpoam>" +
                        "                <tunnel-type>primary</tunnel-type>" +
                        "                <me-name>" + busiSrtpXmlVo.getWorkMeName() + "</me-name>" +// 与工作名称一致
                        "              </vpoam>" +
                        "              <vpoam>" +
                        "                <tunnel-type>backup</tunnel-type>" +
                        "                <me-name>" + busiSrtpXmlVo.getProMeName() + "</me-name>" +
                        "              </vpoam>" +
                        "            </vpoams>" +
                        "            <loop-block>disable</loop-block>" +//   默认
                        "          </tunnel-te>" +
                        "        </mpls-te>" +
                        "      </mpls>";

                logger.info("业务管理srtp激活xml为：{}", xml3);
                isSend = deviceManager.editConfig(xml3, "merge");
            }
        }
        return isSend;
    }

    /**
     * 以太无保护
     *
      <mpls xmlns="http://fiberhome.com/fhnw/yang/mplsprotocol/fos-mpls">
        <static-sr>
          <static-sr-adjacency nc:operation="create">
            <nexthop>6.6.6.7</nexthop>下一跳地址
        <out-ifname>eth-1gi0/1/0/5</out-ifname> 端口名称
        <sid-value>20</sid-value> 取源宿邻接标签
        </static-sr-adjacency>
        </static-sr>
        <mpls-te/>
      </mpls>

   <mpls xmlns="http://fiberhome.com/fhnw/yang/mplsprotocol/fos-mpls">
        <static-sr>
          <static-sr-adjacency nc:operation="create">
            <nexthop>6.6.6.6</nexthop>
            <out-ifname>eth-1gi0/1/0/5</out-ifname>
            <sid-value>20</sid-value>
          </static-sr-adjacency>
        </static-sr>
        <mpls-te/>
      </mpls>

     <mpls xmlns="http://fiberhome.com/fhnw/yang/mplsprotocol/fos-mpls">
     <mpls-te>
     <tunnel-te nc:operation="create">
     <id>2</id> //取tunnelId
     <loop-block>disable</loop-block>
     </tunnel-te>
     </mpls-te>
     </mpls>

     <mpls xmlns="http://fiberhome.com/fhnw/yang/mplsprotocol/fos-mpls">
     <mpls-te>
     <tunnel-te nc:operation="create">
     <id>2</id>//取tunnelId
     <loop-block>disable</loop-block>
     </tunnel-te>
     </mpls-te>
     </mpls>

      */

    private boolean sendXml2(BusiSrtpElementVo busiSrtpElementVo, String elementId) {
        NetElement netElement = netElementService.getCacheObject(elementId);
        Device device = deviceManager.getDevice(netElement.getIp());
        if (device.isConnected()) {
            if ("无保护".equals(busiSrtpElementVo.getProtectType())) {
                return sendNoProtectXml2(busiSrtpElementVo, elementId);
            } else {
                return sendProtectXml2(busiSrtpElementVo, elementId);
            }
        }
        return false;

    }


    /**
     * 拼接无保护报文并发送
     * @param busiSrtpElementVo
     * @param elementId
     * @return
     */
    private boolean sendNoProtectXml2(BusiSrtpElementVo busiSrtpElementVo, String elementId) {
        BusiSrtpXmlVo busiSrtpXmlVo = new BusiSrtpXmlVo();
        boolean isSend = true;
        //判断网元类型（源宿、过站）  判断激活/去激活组装报文
        //路由表中查询邻接标签 已在邻接标签中前置下发
       /* BusiSrtpRouteTable busiSrtpRouteTable = new BusiSrtpRouteTable();
        busiSrtpRouteTable.setSrtpId(busiSrtpElementVo.getSrtpId());
        busiSrtpRouteTable.setElementId(elementId);
        busiSrtpRouteTable.setRouteDirection("1");
        busiSrtpRouteTable.setRouteType("1");
        List<BusiSrtpRouteListVoTable> busiSrtpRouteTableList = busiSrtpRouteTableService.selectBusiSrtpRouteTableList(busiSrtpRouteTable);
        if (!CollectionUtils.isEmpty(busiSrtpRouteTableList)){
            //正常就一条数据
            busiSrtpElementVo.setNeighbLabel(busiSrtpRouteTableList.get(0).getNeighbLabel());
        }
        BusiNeighbLabelListVo neibLabelXmlResult = busiNeighbLabelService.findNeibLabelXmlByParams(elementId, busiSrtpRouteTableList.get(0).getPortId());
        if ("1".equals(busiSrtpElementVo.getElementType())){
            busiSrtpXmlVo.setWorkNextHop(neibLabelXmlResult.getStartOppositeIp());
            busiSrtpXmlVo.setWorkOutIfName(neibLabelXmlResult.getStartPortName());
            busiSrtpXmlVo.setNeighbLabel(neibLabelXmlResult.getStartNeighbLabel());

        }else if ("2".equals(busiSrtpElementVo.getElementType())){
            busiSrtpXmlVo.setWorkNextHop(neibLabelXmlResult.getEndOppositeIp());
            busiSrtpXmlVo.setWorkOutIfName(neibLabelXmlResult.getEndPortName());
            busiSrtpXmlVo.setNeighbLabel(neibLabelXmlResult.getEndNeighbLabel());
        }else if ("3".equals(busiSrtpElementVo.getElementType())){

        }*/
        if("1".equals(busiSrtpElementVo.getStatus())){
            if ("1".equals(busiSrtpElementVo.getElementType()) || "2".equals(busiSrtpElementVo.getElementType())){

                String noProXml2 = "<mpls xmlns=\"http://fiberhome.com/fhnw/yang/mplsprotocol/fos-mpls\">" +
                        "        <mpls-te>" +
                        "          <tunnel-te nc:operation=\"create\">" +
                        "            <id>"+busiSrtpElementVo.getPositiveTunnelId()+"</id>" +//取tunnelId
                        "            <loop-block>disable</loop-block>" +
                        "          </tunnel-te>" +
                        "        </mpls-te>" +
                        "      </mpls>";
                logger.info("srtp-无保护-源宿无保护tunnel激活报文数据noProxml1：" + noProXml2.toString());
                isSend = deviceManager.editConfig(noProXml2, "merge");
                logger.info("isSend结果===================================================：" + isSend);

            }else if ("3".equals(busiSrtpElementVo.getElementType())){
                //过站网元
            }
        }else {
            //去激活  提供的srtp参考报文无内容，待测试
            if ("1".equals(busiSrtpElementVo.getElementType()) || "2".equals(busiSrtpElementVo.getElementType())){
                String xml5 = "<mpls xmlns=\"http://fiberhome.com/fhnw/yang/mplsprotocol/fos-mpls\">" +
                        "        <mpls-te>" +
                        "          <tunnel-te nc:operation=\"remove\">" +
                        "            <id>" + busiSrtpElementVo.getPositiveTunnelId() + "</id>" +//从主表信息获取
                        "          </tunnel-te>" +
                        "        </mpls-te>" +
                        "      </mpls>";
                logger.info("srtp-tunnel去激活报文数据xml5：" + xml5.toString());
                boolean isSend5 = deviceManager.editConfig(xml5, "merge");
                logger.info("isSend5结果===================================================：" + isSend5);
            }else {
                //过站网元
            }
        }


        return isSend;
    }
    /**
     * 拼接保护报文并发送
     * @param busiSrtpElementVo
     * @param elementId
     * @return
     */
    private boolean sendProtectXml2(BusiSrtpElementVo busiSrtpElementVo, String elementId) {
        boolean isSend = true;
        if ("1".equals(busiSrtpElementVo.getElementType()) || "2".equals(busiSrtpElementVo.getElementType())){
            BusiSrtpXmlVo busiSrtpXmlVo = new BusiSrtpXmlVo();
            ElementBusiSrtpAlarmoam oam = new ElementBusiSrtpAlarmoam();
            oam.setSrtpId(busiSrtpElementVo.getSrtpId());
            //网元id
            oam.setElementId(elementId);
            //获取oam工作属性
            oam.setRouteType("1");
            List<ElementBusiSrtpAlarmoamVo> workOamList = elementBusiSrtpAlarmoamService.selectElementBusiSrtpAlarmoamList(oam);
            if (workOamList.size()>0){
                busiSrtpXmlVo.setWorkMegName(workOamList.get(0).getMegName());
                busiSrtpXmlVo.setWorkLevel("7");
                busiSrtpXmlVo.setWorkIcc("123456");
                busiSrtpXmlVo.setWorkUmc("789ABC");
                busiSrtpXmlVo.setWorkMeName(workOamList.get(0).getMeName());
                busiSrtpXmlVo.setWorkMepId(workOamList.get(0).getMeName());//?
                busiSrtpXmlVo.setWorkRemoteMepId(workOamList.get(0).getMeName());
                busiSrtpXmlVo.setWorkCcmInterval(workOamList.get(0).getCv().replace(".","_"));
                busiSrtpXmlVo.setWorkOamExp(workOamList.get(0).getLspTtl().split("/")[1]);
                busiSrtpXmlVo.setWorkOamTtl(workOamList.get(0).getLspTtl().split("/")[0]);
            }
            //获取oam保护属性

            oam.setRouteType("2");
            List<ElementBusiSrtpAlarmoamVo> proOamList = elementBusiSrtpAlarmoamService.selectElementBusiSrtpAlarmoamList(oam);
            if (proOamList.size()>0){
                busiSrtpXmlVo.setProMegName(proOamList.get(0).getMegName());
                busiSrtpXmlVo.setProLevel("7");
                busiSrtpXmlVo.setProIcc("123456");
                busiSrtpXmlVo.setProUmc("789ABC");
                busiSrtpXmlVo.setProMeName(proOamList.get(0).getMeName());
                busiSrtpXmlVo.setProMepId(proOamList.get(0).getMeName());//?
                busiSrtpXmlVo.setProRemoteMepId(proOamList.get(0).getMeName());
                busiSrtpXmlVo.setProCcmInterval(proOamList.get(0).getCv().replace(".","_"));
                busiSrtpXmlVo.setProOamExp(proOamList.get(0).getLspTtl().split("/")[1]);
                busiSrtpXmlVo.setProOamTtl(proOamList.get(0).getLspTtl().split("/")[0]);

            }
                if ("1".equals(busiSrtpElementVo.getStatus())){
                    //工作路径-oam srtp默认带保护
                    String workOamXml = "<tpoam xmlns=\"http://fiberhome.com/fhnw/yang/oam/fos-tpoam\">" +
                            "        <meg-cfg>" +
                            "          <meg-list>" +
                            "            <meg-name>" + busiSrtpXmlVo.getWorkMegName() + "</meg-name>" +//关键字，string 1-31  meg+十位数字转16进制
                            "            <level>7</level>" +//MEG级别0-7
                            "            <icc>123456</icc>" +//sting,1-6
                            "            <umc>789ABC</umc>" +//string,1-6
                            "            <me-list>" +
                            "              <me-name>" + busiSrtpXmlVo.getWorkMeName() + "</me-name>" +//关键字 me
                            "              <mep-id>" + busiSrtpXmlVo.getWorkMepId() + "</mep-id>" +//源MEP ID，1-8191   取倒数二 三  工作下的两条数据相反    1/2/7  2/1/7    保护下的两条数据相反
                            "              <remote-mep-id>" + busiSrtpXmlVo.getWorkRemoteMepId() + "</remote-mep-id>" +//目的MEP ID，1-8191
                            "              <mp-type>mep</mp-type>" +//节点类型，源宿取值mep,
                            "              <ccm-send-enable>enable</ccm-send-enable>" +//CCM发送使能
                            "              <ccm-interval>" + busiSrtpXmlVo.getWorkCcmInterval() + "</ccm-interval>" +//CCM 发送间隔   3.33 .替换为下划线
                            "              <aps-send-enable>disable</aps-send-enable>" +//APS 使能
                            "              <fdi-send-enable>disable</fdi-send-enable>" +//FDI使能
                            "              <csf-send-enable>disable</csf-send-enable>" +//CSF使能   写死
                            "              <oam-exp>" + busiSrtpXmlVo.getWorkOamExp() + "</oam-exp>" +//OAM的EXP配置，uint8，0-7    LSP TTL/EXP
                            "              <oam-ttl>" + busiSrtpXmlVo.getWorkOamTtl() + "</oam-ttl>" +//OAM 的TTL uint8,1-255     LSP TTL/EXP
                            "              <dual-lm-enable>disable</dual-lm-enable>" +//双向LM使能  写死
                            "            </me-list>" +
                            "          </meg-list>" +
                            "        </meg-cfg>" +
                            "      </tpoam>";
                    logger.info("srtp激活workOamXml为：{}", workOamXml);
                    isSend = deviceManager.editConfig(workOamXml, "merge");
                    logger.info("isSend结果===================================================：" + isSend);
                    //保护路径-oam
                    String proOamXml = " <tpoam xmlns=\"http://fiberhome.com/fhnw/yang/oam/fos-tpoam\">" +
                            "        <meg-cfg>" +
                            "          <meg-list>" +
                            "            <meg-name>" + busiSrtpXmlVo.getProMegName() + "</meg-name>" +//关键字，string 1-31  meg+十位数字转16进制
                            "            <level>7</level>" +//MEG级别0-7
                            "            <icc>123456</icc>" +//sting,1-6
                            "            <umc>789ABC</umc>" +//string,1-6
                            "            <me-list>" +
                            "              <me-name>" + busiSrtpXmlVo.getProMeName() + "</me-name>" +//关键字 me
                            "              <mep-id>" + busiSrtpXmlVo.getProMepId() + "</mep-id>" +//源MEP ID，1-8191   取倒数二 三  工作下的两条数据相反    1/2/7  2/1/7    保护下的两条数据相反
                            "              <remote-mep-id>" + busiSrtpXmlVo.getProRemoteMepId() + "</remote-mep-id>" +//目的MEP ID，1-8191
                            "              <mp-type>mep</mp-type>" +//节点类型，源宿取值mep,
                            "              <ccm-send-enable>enable</ccm-send-enable>" +//CCM发送使能
                            "              <ccm-interval>" + busiSrtpXmlVo.getProCcmInterval() + "</ccm-interval>" +//CCM 发送间隔   3.33 .替换为下划线
                            "              <aps-send-enable>disable</aps-send-enable>" +//APS 使能
                            "              <fdi-send-enable>disable</fdi-send-enable>" +//FDI使能
                            "              <csf-send-enable>disable</csf-send-enable>" +//CSF使能   写死
                            "              <oam-exp>" + busiSrtpXmlVo.getProOamExp() + "</oam-exp>" +//OAM的EXP配置，uint8，0-7    LSP TTL/EXP
                            "              <oam-ttl>" + busiSrtpXmlVo.getProOamTtl() + "</oam-ttl>" +//OAM 的TTL uint8,1-255     LSP TTL/EXP
                            "              <dual-lm-enable>disable</dual-lm-enable>" +//双向LM使能  写死
                            "            </me-list>" +
                            "          </meg-list>" +
                            "        </meg-cfg>" +
                            "      </tpoam>";
                    logger.info("srtp激活proOamXml为：{}", proOamXml);
                    isSend = deviceManager.editConfig(proOamXml, "merge");
                    logger.info("isSend结果===================================================：" + isSend);

                    String tunnelXml = " <mpls xmlns=\"http://fiberhome.com/fhnw/yang/mplsprotocol/fos-mpls\">" +
                            "        <mpls-te>" +
                            "          <tunnel-te nc:operation=\"create\">" +
                            "            <id>"+busiSrtpElementVo.getPositiveTunnelId()+"</id>" +
                            "            <revertive-mode>revertive</revertive-mode>" +
                            "            <wtr>5</wtr>" +
                            "            <holdoff-time>0</holdoff-time>" +
                            "            <vpoams xmlns=\"http://fiberhome.com/fhnw/yang/oam/fos-tpoam\">" +
                            "              <vpoam>" +
                            "                <tunnel-type>primary</tunnel-type>" +
                            "                <me-name>"+busiSrtpXmlVo.getWorkMeName()+"</me-name>" +
                            "              </vpoam>" +
                            "              <vpoam>" +
                            "                <tunnel-type>backup</tunnel-type>" +
                            "                <me-name>"+busiSrtpXmlVo.getProMeName()+"</me-name>" +
                            "              </vpoam>" +
                            "            </vpoams>" +
                            "            <loop-block>disable</loop-block>" +
                            "          </tunnel-te>" +
                            "        </mpls-te>" +
                            "      </mpls>";
                    logger.info("srtp激活有保护tunnelXml为：{}", tunnelXml);
                    isSend = deviceManager.editConfig(tunnelXml, "merge");
                    logger.info("isSend结果===================================================：" + isSend);
                }else{
                    //去激活
                        String oamInActXml = "<mpls xmlns=\"http://fiberhome.com/fhnw/yang/mplsprotocol/fos-mpls\">" +
                                "        <mpls-te>" +
                                "          <tunnel-te nc:operation=\"create\">" +
                                "            <id>"+busiSrtpElementVo.getPositiveTunnelId()+"</id>" +
                                "            <revertive-mode nc:operation=\"remove\">revertive</revertive-mode>" +
                                "            <wtr nc:operation=\"remove\">5</wtr>" +
                                "            <holdoff-time nc:operation=\"remove\">0</holdoff-time>" +
                                "            <vpoams xmlns=\"http://fiberhome.com/fhnw/yang/oam/fos-tpoam\">" +
                                "              <vpoam nc:operation=\"remove\">" +
                                "                <tunnel-type>primary</tunnel-type>" +
                                "                <me-name>"+busiSrtpXmlVo.getWorkMeName()+"</me-name>" +
                                "              </vpoam>" +
                                "              <vpoam nc:operation=\"remove\">" +
                                "                <tunnel-type>backup</tunnel-type>" +
                                "                <me-name>"+busiSrtpXmlVo.getProMeName()+"</me-name>" +
                                "              </vpoam>" +
                                "            </vpoams>" +
                                "            <loop-block>disable</loop-block>" +
                                "          </tunnel-te>" +
                                "        </mpls-te>" +
                                "      </mpls>";
                        logger.info("srtp去激活有保护oamInActXml为：{}", oamInActXml);
                        isSend = deviceManager.editConfig(oamInActXml, "merge");
                        logger.info("isSend结果===================================================：" + isSend);

                        String oamMegWorkInActXml = "  <tpoam xmlns=\"http://fiberhome.com/fhnw/yang/oam/fos-tpoam\">" +
                                "        <meg-cfg>" +
                                "          <meg-list nc:operation=\"remove\">" +
                                "            <meg-name>"+busiSrtpXmlVo.getWorkMegName()+"</meg-name>" +
                                "          </meg-list>" +
                                "        </meg-cfg>" +
                                "      </tpoam>";

                        logger.info("srtp去激活有保护oamMegWorkInActXml为：{}", oamMegWorkInActXml);
                        isSend = deviceManager.editConfig(oamMegWorkInActXml, "merge");
                        logger.info("isSend结果===================================================：" + isSend);

                        String oamMegPorInActXml = "  <tpoam xmlns=\"http://fiberhome.com/fhnw/yang/oam/fos-tpoam\">" +
                                "        <meg-cfg>" +
                                "          <meg-list nc:operation=\"remove\">" +
                                "            <meg-name>"+busiSrtpXmlVo.getProMegName()+"</meg-name>" +
                                "          </meg-list>" +
                                "        </meg-cfg>" +
                                "      </tpoam>";
                        logger.info("srtp去激活有保护oamMegPorInActXml为：{}", oamMegPorInActXml);
                        isSend = deviceManager.editConfig(oamMegPorInActXml, "merge");
                        logger.info("isSend结果===================================================：" + isSend);

                }
                    return isSend;

            }else{
            //过站 静态sr邻接配置（已前置配置）

                return isSend;
            }

    }

}

